package dryven.view.engine.expression.nodelisters;

import java.util.Map;

import dryven.reflection.ClassTypeRef;
import dryven.reflection.TypeRef;

public class DefaultNodeListerFactory implements ExpressionNodeFactory {

	@Override
	public NodeLister create(TypeRef t) {
		if(t.isPrimitive()) {
			return new PrimitiveNodeLister();
		}
		if(t.implementsInterface(new ClassTypeRef(Map.class))) {
			return new MapNodeLister(t, this);
		}
		else {
			return new ObjectNodeLister(t, this);
		}
	}

	@Override
	public TypeRef convertType(String type) {
		Class<?> clazz;
		try {
			clazz = Class.forName(type);
		} catch (ClassNotFoundException e) {
			throw new RuntimeException(e);
		}
		return new ClassTypeRef(clazz);
	}

}
